package com.example.jikeyoujikeyou.office_sz.comment.utils;

import com.example.jikeyoujikeyou.office_sz.view.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

public class ActivityTask {
    static List<BaseActivity> list = new ArrayList<>();

    public static ActivityTask getInstance() {
        return Instance.instance;
    }

    private static class Instance {
        static ActivityTask instance = new ActivityTask();
    }

    /**
     * 将activity添加到管理栈中
     * activity
     *
     * @param activity
     */
    public void addActivity(BaseActivity activity) {
        if (list.contains(activity)) {
            list.remove(activity);
        }
        list.add(activity);
    }

    /**
     * 将activity移除出栈创建的时候添加
     * activity销毁的时候移除
     *
     * @param activity
     * @return
     */
    public boolean removeActivity(BaseActivity activity) {
        if (list.contains(activity)) {
            list.remove(activity);
            return true;
        }
        return false;
    }

    /**
     * 获取当前现实activity的引用
     *
     * @return
     */
    public BaseActivity getCurrentShowActivity() {
        if (ListValidate.isEmpty(list)) {
            return null;
        }
        return list.get(list.size() - 1);
    }
}
